home *** CD-ROM | disk | FTP | other *** search
- /*
- *--- CMIDIInputPort.c -----------------------------------------------------------------
- * Copyright © Paul Ferguson, 1990, 1991, 1992. All rights reserved.
- *
- * Superclass: CDataPort
- * Subclasses: None
- *
- * Description:
- * CMIDIInputPort.c defines a MIDI Manager port object.
- *
- * For use with THINK C 5.0, the accompanying THINK Class Library (TCL), and MIDI
- * Manager 2.0. Refer to the accompanying Microsoft Word document for complete
- * details about MIDI Manager objects.
- *
- * If you have comments or questions about this code, you can reach me on
- * CompuServe at 70441,3055.
- *
- *--------------------------------------------------------------------------------------
- *---- NOTE --- NOTE --- NOTE --- NOTE --- NOTE --- NOTE --- NOTE --- NOTE --- NOTE ----
- *--------------------------------------------------------------------------------------
- * If you are not familiar with programming the Apple MIDI Manager, refer to the
- * "MIDI Management Tools" Version 2.0, available from APDA. You MUST have the
- * software (MIDI.H and the library) from this package in order to use these objects.
- * It will not work without this.
- *--------------------------------------------------------------------------------------
- * REVISION HISTORY:
- * August ??, 1990 - Original release (1.0).
- * November 5, 1990 - Added checks for midiMgrVer to most methods.
- * August 1991 - updated for THINK C 5.0 as version 2.0
- *--------------------------------------------------------------------------------------
- */
-
- #include "CMIDIInputPort.h" // This code's header file
-
- #define midiPoll 104 // From MIDI.a
- #define midiDiscardPacket 176
-
- static pascal void (*CMIDIInputPort::midiDiscardProc) (short theRefNum, MIDIPacketPtr thePacket);
- static pascal void (*CMIDIInputPort::midiPollProc) (short theRefNum, long theOffsetTime);
- static pascal void (*CMIDIInputPort::midiFlushProc) (short theRefNum);
-
- /*
- *--- CMIDIInputPort::IMIDIInputPort ------------------------------------------
- * Initialize Input Port. This method sets up the MIDIPortParams data structure
- * and calls CMIDIPort::IMIDIPort().
- *-----------------------------------------------------------------------------
- */
- OSErr CMIDIInputPort::IMIDIInputPort(StringPtr theName,
- OSType thePortID,
- Boolean theVisibleFlag,
- CMIDITimePort * theTimePort,
- long theOffset,
- short theBufSize,
- ProcPtr theReadHook)
- {
- MIDIPortParams portParams; // MIDI Mgr Init data structure
- OSErr theResult;
-
- portParams.portID = thePortID;
- portParams.portType = midiPortTypeInput;
- if ( (theVisibleFlag == FALSE) && (itsVersion >= 0x0200) ) // Invisible input port, in 2.x
- portParams.portType |= midiPortInvisible;
-
- portParams.timeBase = theTimePort ? theTimePort->GetRefNum() : 0;
- portParams.offsetTime = theOffset;
- portParams.readHook = (Ptr) theReadHook;
- portParams.refCon = SetCurrentA5();
- BlockMove(theName, portParams.name, theName[0]+1);
-
- theResult = IMIDIPort(&portParams, theBufSize);
- if (itsVersion >= 0x0200)
- {
- midiDiscardProc = MIDICallAddress(midiDiscardPacket);
- midiPollProc = MIDICallAddress(midiPoll);
- }
- return theResult;
- }
-
- void CMIDIInputPort::Flush(void)
- {
- if (itsVersion >= 0x0200)
- (*midiFlushProc) (itsRefNum);
- else
- if (itsVersion) MIDIFlush(itsRefNum);
- }
-
- ProcPtr CMIDIInputPort::GetReadHook(void)
- {
- return (itsVersion ? MIDIGetReadHook(itsRefNum) : 0);
- }
-
- void CMIDIInputPort::SetReadHook(ProcPtr theReadHook)
- {
- if (itsVersion)
- MIDISetReadHook(itsRefNum, theReadHook);
- }
-
- void CMIDIInputPort::Poll(long offsetTime)
- {
- if (itsVersion >= 0x0200)
- {
- (*midiPollProc) (itsRefNum, offsetTime);
- }
- else
- {
- if (itsVersion)
- MIDIPoll(itsRefNum, offsetTime);
- }
- }
-
- void CMIDIInputPort::DiscardPacket(MIDIPacketPtr thePacket)
- {
- if (itsVersion >= 0x0200) // Only valid on MM 2.0 or later!
- (*midiDiscardProc) (itsRefNum, thePacket);
- }
-
- // end of CMIDIInputPort.c
-